Python String index()

34

myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))


## OUTPUT:

-1
Traceback (most recent call last):
  File "D:\Programming\python\article\find.py", line 38, in <module>
    print(myStr.index("js"))
ValueError: substring not found
myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))
myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))
myStr = "py py py py"
print(myStr.find("js"))
print(myStr.index("js"))

Comments

Submit
0 Comments